import axios from 'axios'
import {
    Message
} from 'element-ui'

const instance = axios.create({
    timeout: 300000
})

instance.interceptors.request.use(config => {
    return config
}, error => {
    Promise.reject(error)
})

instance.interceptors.response.use(response => {
    const res = response.data
        // console.log(res,"请求响应")

    if (res.code === '402' || res.code === '403' || res.code === '405' || res.code === '500') {
        Message.warning({
            message: response.data.message,
            duration: 3500
        })
    } else {
        return res
    }
}, error => {
    let data = error.response.data.data
    let msg = '请求失败'
    if (data && typeof data === 'string') {
        data = JSON.parse(data) || {}
        msg = data.msg
    }
    Message.error({
        message: msg,
        duration: 3500
    })
})
export default instance